﻿namespace IS.Projecto.DataAccessLayer.impl
{
    using System.Collections.Generic;
    using Modelo;
    using Spring.Data.NHibernate.Support;

    public class GenericDao<T> : HibernateDaoSupport, IGenericDao<T> where T : Entidade
    {
        public T Read(object id)
        {
            return Session.Get<T>(id);
        }

        public void Write(T instance)
        {
            Session.SaveOrUpdate(instance);
        }

        public void Delete(T instance)
        {
            Session.Delete(instance);
        }

        public IList<T> GetAll()
        {
            return Session.CreateCriteria(typeof(T)).List<T>();
        }
    }
}